/**
 * Copyright (c) 2010 XXXXX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.edu.itba.ia2010.geneticos.motor.api.utils;

import java.util.Random;

import org.apache.commons.lang.Validate;

/**
 * {@link Random} util para las pruebas de unidad.
 * 
 * 
 * @author Juan F. Codagnone
 * @since Mar 21, 2010
 */
public class FixedRandom extends Random {
    private static final long serialVersionUID = -6408354339952230016L;
    
    private final double[] numbers;
    private int nNumbers = 0;
    private final boolean[] booleans;
    private int nBooleans = 0;
    private int [] integers;
    private int nIntegers = 0;
    
    /** consturctor para {@link Random#nextDouble()} */
    public FixedRandom(final double []numbers) {
        this(numbers, new boolean[]{}, new int[]{});
    }

    /** consturctor para {@link Random#nextBoolean()} */
    public FixedRandom(final boolean []booleans) {
        this(new double []{}, booleans, new int[]{});
    }
    
    /** consturctor para {@link Random#nextBoolean()} */
    public FixedRandom(final int []ints) {
        this(new double []{}, new boolean[]{}, ints);
    }
    
    
    /** constructor generico */
    public FixedRandom(final double []numbers, final boolean []booleans,
            final int []integers) {
        Validate.notNull(numbers);
        Validate.notNull(booleans);
        Validate.notNull(integers);
        
        this.numbers = numbers;
        this.booleans = booleans;
        this.integers = integers;
    }
    
    /** Va devolviendo valores fijos */
    public final double nextDouble() {
        return numbers[nNumbers++];
    }
    
    /** Va devolviendo valores fijos */
    public final boolean nextBoolean() {
        return booleans[nBooleans++];
    }
    
   /** @see java.util.Random#nextInt(int) */
    @Override
    public final int nextInt(final int n) {
        return Math.min(integers[nIntegers++], n - 1);
}

    /** @see Random#nextInt() */
    @Override
    public final int nextInt() {
        return integers[nIntegers++];
    }
}
